package com.itheima.apitest.datetest2;
//JDK8时间日期类对象(三种)获取,各种属性获取
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;

public class DateTest {
    public static void main(String[] args) {
        LocalDateTime now = LocalDateTime.now();
        System.out.println(now);
        LocalDateTime localDateTime = LocalDateTime.of(2020, 11, 11, 11, 11, 11);
        System.out.println(localDateTime);
        // 获取年
        int year = now.getYear();
        System.out.println(year);
        // 获取月份（1-12）
        int monthValue = localDateTime.getMonthValue();
        System.out.println(monthValue);
        // 获取月份中的第几天（1-31）
        int dayOfMonth = now.getDayOfMonth();
        System.out.println(dayOfMonth);
        // 获取一年中的第几天（1-366）
        int dayOfYear = localDateTime.getDayOfYear();
        System.out.println(dayOfYear);
        // 获取星期
        DayOfWeek dayOfWeek = now.getDayOfWeek();
        System.out.println(dayOfWeek);
        // 获取分钟
        int minute = localDateTime.getMinute();
        System.out.println(minute);
        // 获取小时
        int hour = now.getHour();
        System.out.println(hour);

        System.out.println("-------------------");
        // 转换成为一个LocalDate对象
        LocalDate localDate = now.toLocalDate();
        System.out.println(localDate);
        // 转换成为一个LocalTime对象
        LocalTime localTime = localDateTime.toLocalTime();
        System.out.println(localTime);
    }
}
